
from isaaclab.assets import ArticulationCfg
from isaaclab.envs import DirectRLEnvCfg
from isaaclab.scene import InteractiveSceneCfg
from isaaclab.sim import SimulationCfg
from isaaclab.sim.simulation_cfg import PhysxCfg
from isaaclab.envs import DirectRLEnvCfg
from isaaclab.utils import configclass
from isaaclab_assets.robots.franka import FRANKA_PANDA_CFG 

@configclass
class FrankaLiftEnvCfg(DirectRLEnvCfg):
    # env
    decimation = 2             # 每2个物理步（physics steps）执行一次策略，相当于降低控制频率
    episode_length_s = 5.0     # 每个episode的最大时长（秒）
    # - spaces definition
    action_space = 9           # 动作空间维度（连续动作空间）
    observation_space = 23      # 观测空间维度
    state_space = 0           

    # physx
    physx_cfg: PhysxCfg = PhysxCfg(bounce_threshold_velocity=0.01, 
                                   gpu_found_lost_aggregate_pairs_capacity=1024 * 1024 * 4,
                                   gpu_total_aggregate_pairs_capacity=16 * 1024,
                                   friction_correlation_distance=0.00625)

    # simulation
    sim: SimulationCfg = SimulationCfg(dt=0.01, render_interval=decimation, physx=physx_cfg) # 物理仿真步长 # 渲染间隔（与策略执行同步）

    # robot(s)
    robot_cfg: ArticulationCfg = FRANKA_PANDA_CFG.replace(prim_path="/World/envs/env_.*/Robot")

    # scene
    scene: InteractiveSceneCfg = InteractiveSceneCfg(num_envs=4096, env_spacing=2.5, replicate_physics=True) # 环境实例之间的间距（单位：米） # 共享物理属性以优化性能

    # custom parameters/scales
    # - controllable joint
    cart_dof_name = "slider_to_cart"
    pole_dof_name = "cart_to_pole"
    # - action scale
    action_scale = 100.0  # [N]
    # - reward scales
    rew_scale_alive = 1.0
    rew_scale_terminated = -2.0
    rew_scale_pole_pos = -1.0
    rew_scale_cart_vel = -0.01
    rew_scale_pole_vel = -0.005
    # - reset states/conditions
    initial_pole_angle_range = [-0.25, 0.25]  # pole angle sample range on reset [rad]
    max_cart_pos = 3.0  # reset if cart exceeds this position [m]